package com.snail.controller;

import com.snail.handler.OnlineUserWebSocketHandler;
import com.snail.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * WebSocket连接管理控制器
 */
@RestController
@RequestMapping("/connections")
@Tag(name = "WebSocket管理", description = "用于管理WebSocket连接")
public class WebSocketController {
    private final OnlineUserWebSocketHandler webSocketHandler;

    public WebSocketController(OnlineUserWebSocketHandler webSocketHandler) {
        this.webSocketHandler = webSocketHandler;
    }

    /**
     * 获取当前WebSocket连接数
     */
    @GetMapping("/connections")
    public Result<Integer> getConnectionCount() {
        return Result.success(webSocketHandler.getSessions().size());
    }

    /**
     * 获取当前在线用户数
     */
    @GetMapping("/online/count")
    public Result<Integer> getOnlineUserCount() {
        return Result.success(webSocketHandler.getOnlineUserCount());
    }
}